package com.holyn.guofang.view.home;

import android.app.Activity;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.CountDownTimer;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.apkfuns.logutils.LogUtils;
import com.holyn.guofang.R;
import com.holyn.guofang.model.constant.AlgorithmTypeConstant;
import com.holyn.guofang.model.webhttp.HttpConfigure;
import com.holyn.guofang.model.webhttp.wo.BrandItemInfoWo;
import com.holyn.guofang.model.webhttp.wo.StatusWo;
import com.holyn.guofang.model.webhttp.wo.TaskIDWo;
import com.holyn.guofang.model.webhttp.wo.UserCardListWo;
import com.holyn.guofang.model.webhttp.wo.UserInfoWo;
import com.holyn.guofang.presenter.BaseView;
import com.holyn.guofang.presenter.brand.BrandContract;
import com.holyn.guofang.presenter.brand.BrandPresenter;
import com.holyn.guofang.utils.MD5Uitl;
import com.holyn.guofang.view.BaseFragment;
import com.holyn.guofang.view.distinguish.AlgorithmSelectActivity;
import com.holyn.guofang.view.distinguish.ImageElementActivity;
import com.holyn.guofang.view.distinguish.ProductClassfiyActivity;
import com.holyn.guofang.view.distinguish.SearchResultListActivity;
import com.holyn.guofang.view.distinguish.SeniorDistinguishActivity;
import com.holyn.guofang.viewcommon.dialog.TaskPayDialog;
import com.holyn.guofang.viewcommon.dialog.ToastDialog;
import com.holyn.guofang.viewcommon.popupwindow.PopupSingleSelectFromBottom;
import com.vondear.rxtools.RxRegUtils;
import com.vondear.rxtools.bean.ActionItem;
import com.vondear.rxtools.view.dialog.RxDialogSure;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * Created by Holyn on 2017/6/13.
 */

public class HomeSearchFragment extends BaseFragment implements BaseView, BrandContract.SearchTradeView{
    private static final int REQUEST_ACTION_POST_TASK_ID = 0x0001;
    private static final int REQUEST_ACTION_POST_SEARCH_REULT_BY_TASK_ID = 0x0002;
    private static final int REQUEST_ACTION_POST_SEARCH = 0x0003;

    /**
     * 2.3.8 判断返回参数 userCard ,如果该字段 内容为空，代表卡已过期，非空则代表未过期
     */
    private static final int REQUEST_ACTION_POST_USER_INFO = 0x0005;
    /**
     * 卡已过期
     * 2.5.6 获取用户的国方卡信息,请求后只做提示
     * 1.1.1—>如果 个数 大于 0 则 ，提示  当前国方卡已过期，请前往 我的-用卡管理 激活卡。
     * 1.1.2—>如果等于0，则提示  当前国方卡已过期，请前往 我的-购国方卡 购卡。
     */
    private static final int REQUEST_ACTION_POST_USER_CARD_LIST = 0x0006;
    /**
     * 卡未过期，根据2.3.8 返回的validMethod进行判断
     * 1.1->当validMethod=0 时，弹出界面，输入的密码需要md5加密。注意这个密码是在激活卡时（我的-用卡管理），当用户选择密码验证 时，需要弹框让用户设定密码，并非登录密码。
     * 1.2->当validMethod=1 时，弹出界面，点获取验证码按钮 对应接口 2.4.17 获取任务支付验证码
     * 1.3->当validMethod=2时，空值，这个就不用弹界面了，直接调用2.4.18接口。
     */
    private static final int REQUEST_ACTION_POST_TASK_PAY_CODE = 0x0007;//2.4.17    选择请求操作任务支付代码
    private static final int REQUEST_ACTION_POST_TASK_PAY = 0x0008;//2.4.18         请求行动后任务支付

    /*  请求代码图像元素
        请求代码获取类代码
        请求代码算法选择
        */
    public static final int REQUEST_CODE_IMAGE_ELEMENT = 0x0001;
    public static final int REQUEST_CODE_GET_CLASSFIY_CODE = 0x0002;
    public static final int REQUEST_CODE_ALGORITHM_SELECT = 0x0003;

    @BindView(R.id.ll_SearchType_select)
    LinearLayout llSearchTypeSelect;
    @BindView(R.id.tv_search_type_name)
    TextView tvSearchTypeName;
    @BindView(R.id.et_Content)
    EditText etContent;
    @BindView(R.id.ll_image_element_select)
    LinearLayout llImageElementSelect;
    @BindView(R.id.btn_reset)
    Button btnReset;
    @BindView(R.id.tv_mark_select)
    TextView tvMarkSelect;
    @BindView(R.id.iv_is_show_tv_mark_select_value)
    ImageView ivIsShowTvMarkSelectValue;
    @BindView(R.id.tv_mark_select_value)
    TextView tvMarkSelectValue;
    @BindView(R.id.tv_algorithm_select)
    TextView tvAlgorithmSelect;
    @BindView(R.id.iv_is_show_tv_algorithm_select_value)
    ImageView ivIsShowTvAlgorithmSelectValue;
    @BindView(R.id.tv_algorithm_select_value)
    TextView tvAlgorithmSelectValue;
    @BindView(R.id.btn_submit)
    Button btnSubmit;

    private int pageSize = 20;
    /**
     * 提交商标查询任务。(商标查询)
     *
     * @param TaskID 任务 ID，由客户端请求前产生
     * @param FrontCount 首次返回前面记录数量
     * @param SearchMode 查询模式(0:混合 1：图形特征 2：文字内容)备注：此参数在普通查询时，只用写死参数值为0，不需选择。
     * @param SearchType 查询条件类型，默认为0。例如：0（商标名称中文），1（商标名称西文）以此类推;
     * @param Content 查询条件内容
     * @param MarkClass 类别
     * @param MarkGroup 群组
     * @param QueryMode 查询方式 (混合、近似、自定义)
     * @param Algorithm 查询算法, 根据参数“QueryMode”确定具体参数 请查阅《查询算法》
     * @param State 状态过滤（0.全部，1.有效，2.无效，3.待定）。，默认0；
     * @param DateType 过滤日期（0.不过滤、1.申请日期、2.初审公告日、3.注册公告日）。默认0
     * @param BeginDate 过滤起始日期，DateType 为“不过滤”时此值为 空，日期格式为:yyyy-mm-dd
     * @param EndDate 过滤截止日期，DateType 为“不过滤”时此值为 空，日期格式为:yyyy-mm-dd
     *
     * @return 操作是否成功(1:是，0:否，-1:用户不存在，-2: 登录信息不存在，-3:用户 ID 与登录信息不匹配， -4:登录已过期，-5:验证码不匹配)
     */
    Integer TaskID;
    Integer FrontCount = pageSize;
    String SearchMode = "0";
    String SearchType = "0";
    String Content = "";
    String MarkClass = "";
    String MarkGroup = "";
    String QueryMode = "0";
    String Algorithm = "";
    String State = "0";
    String DateType = "0";
    String BeginDate = "";
    String EndDate = "";

    private BrandContract.Presenter presenter;
    private MyCountDownTimer timer;

    private PopupSingleSelectFromBottom popupleSelectSearchType;
    private List<String> searchTypeNameList = new ArrayList<>();
    private String searchTypeDefault = AlgorithmTypeConstant.TYPE_ARRAY_SEARCH[0];
    private List<String> searchTypeAddList = new ArrayList<>();
    private int curSelectSearchTypePosition = 0;

    private boolean isShowTvMarkSelectValue = true;
    private boolean isShowTvAlgorithmSelectValue = true;

    private UserInfoWo.UserInfoBean.UserCardBean cardBean;

    private BrandItemInfoWo brandItemInfoWo;

    private TaskPayDialog passwordTaskPayDialog = null;
    private TaskPayDialog validCodeTaskPayDialog = null;

    @Override
    protected int getLayoutResID() {
        return R.layout.fragment_home_search;
    }

    @Override
    protected void initData() {
        presenter = new BrandPresenter(this);
        presenter.addSearchTradeView(this);

        for (String searchTypeName: AlgorithmTypeConstant.TYPE_VALUE_ARRAY_SEARCH){
            searchTypeNameList.add(searchTypeName);
        }
    }

    @Override
    protected void initView() {
        initPopupleSelectSearchType();
    }

    private void initPopupleSelectSearchType(){
        popupleSelectSearchType = new PopupSingleSelectFromBottom(getActivity(), "选择查询类型", searchTypeNameList);
        popupleSelectSearchType.setOnItemClickListener(new PopupSingleSelectFromBottom.OnItemClickListener() {
            @Override
            public void onItemClick(String item, int position) {
                curSelectSearchTypePosition = position;
                String typeSearch = AlgorithmTypeConstant.TYPE_ARRAY_SEARCH[position];
                searchTypeDefault = typeSearch;
//                toastMsg("searchTypeDefault:"+searchTypeDefault);//选择调试
                tvSearchTypeName.setText(AlgorithmTypeConstant.TYPE_VALUE_ARRAY_SEARCH[position]);

                etContent.setText("");
                if (position == 2){//图形要素
                    etContent.setEnabled(false);
                    llImageElementSelect.setVisibility(View.VISIBLE);
                    etContent.setHint("请点击右边按钮");
                } else {
                    etContent.setEnabled(true);
                    llImageElementSelect.setVisibility(View.GONE);
                    etContent.setHint("请输入查询内容");
                }
                reSetData(false);
            }
        });
    }

    @OnClick({R.id.ll_SearchType_select, R.id.ll_image_element_select, R.id.btn_reset, R.id.tv_mark_select, R.id.iv_is_show_tv_mark_select_value, R.id.tv_algorithm_select, R.id.iv_is_show_tv_algorithm_select_value, R.id.btn_submit})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.ll_SearchType_select:
                popupleSelectSearchType.showPopupWindow();
                break;
            case R.id.ll_image_element_select:
                ImageElementActivity.startForResult(HomeSearchFragment.this, REQUEST_CODE_IMAGE_ELEMENT);
                break;
            case R.id.btn_reset:
                reSetData(true);
                break;
            case R.id.tv_mark_select:
                ToastDialog toastDialog = new ToastDialog(getActivity(), true, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        ProductClassfiyActivity.startForResult(HomeSearchFragment.this, REQUEST_CODE_GET_CLASSFIY_CODE);
                        dialog.dismiss();
                    }
                });
                toastDialog.setTvContent("商品范围数据将重置");
                toastDialog.show();
                break;
            case R.id.iv_is_show_tv_mark_select_value:
                isShowTvMarkSelectValue = !isShowTvMarkSelectValue;
                if (isShowTvMarkSelectValue){
                    ivIsShowTvMarkSelectValue.setImageResource(R.drawable.ic_expand_up);
                    tvMarkSelectValue.setVisibility(View.VISIBLE);
                } else {
                    ivIsShowTvMarkSelectValue.setImageResource(R.drawable.ic_expand_down);
                    tvMarkSelectValue.setVisibility(View.GONE);
                }
                break;
            case R.id.tv_algorithm_select:
                ArrayList<String> typeList = new ArrayList<>();
                typeList.add(searchTypeDefault);
                AlgorithmSelectActivity.startForResult(HomeSearchFragment.this, false, typeList, REQUEST_CODE_ALGORITHM_SELECT);
                break;
            case R.id.iv_is_show_tv_algorithm_select_value:
                isShowTvAlgorithmSelectValue = !isShowTvAlgorithmSelectValue;
                if (isShowTvAlgorithmSelectValue){
                    ivIsShowTvAlgorithmSelectValue.setImageResource(R.drawable.ic_expand_up);
                    tvAlgorithmSelectValue.setVisibility(View.VISIBLE);
                } else {
                    ivIsShowTvAlgorithmSelectValue.setImageResource(R.drawable.ic_expand_down);
                    tvAlgorithmSelectValue.setVisibility(View.GONE);
                }
                break;
            case R.id.btn_submit:
                submitData();
                break;
        }
    }

    private void reSetData(boolean isContainSearchType){
        if (isContainSearchType){
            tvSearchTypeName.setText(AlgorithmTypeConstant.TYPE_VALUE_ARRAY_SEARCH[0]);

            etContent.setEnabled(true);
            llImageElementSelect.setVisibility(View.GONE);
            etContent.setText("");
            etContent.setHint("请输入查询内容");
        }

        isShowTvMarkSelectValue = true;
        ivIsShowTvAlgorithmSelectValue.setImageResource(R.drawable.ic_expand_up);
        tvMarkSelectValue.setVisibility(View.VISIBLE);
        tvMarkSelectValue.setText("商品服务范围：全类");

        isShowTvAlgorithmSelectValue = true;
        ivIsShowTvAlgorithmSelectValue.setImageResource(R.drawable.ic_expand_up);
        tvAlgorithmSelectValue.setVisibility(View.VISIBLE);
        tvAlgorithmSelectValue.setText("");
        tvAlgorithmSelectValue.append("查询算法：相同\n");
        tvAlgorithmSelectValue.append("状态过滤：全部\n");
        tvAlgorithmSelectValue.append("日期种类：不过滤");

        SearchMode = "2";
        SearchType = "0";
        Content = "";
        MarkClass = "";
        MarkGroup = "";
        QueryMode = "0";
        Algorithm = "";
        State = "0";
        DateType = "0";
        BeginDate = "";
        EndDate = "";
    }
    private void submitData(){
        Content = etContent.getText().toString().trim();
        if (TextUtils.isEmpty(Content)){
            toastMsg("请先添加查询内容");
            return;
        }
        if (curSelectSearchTypePosition == 0 || curSelectSearchTypePosition == 4 || curSelectSearchTypePosition == 6
                || curSelectSearchTypePosition ==8 || curSelectSearchTypePosition == 10){//中文
            if (!RxRegUtils.isChz(Content)){
                toastMsg("查询内容格式错误");
                return;
            }
        } else if (curSelectSearchTypePosition == 1 || curSelectSearchTypePosition == 5 || curSelectSearchTypePosition == 7
                || curSelectSearchTypePosition == 9 || curSelectSearchTypePosition == 11){//英文
            if (!RxRegUtils.isEn(Content)){
                toastMsg("查询内容格式错误");
                return;
            }
        }

        presenter.postUserInfo(REQUEST_ACTION_POST_USER_INFO);
//        presenter.postTaskID(REQUEST_ACTION_POST_TASK_ID);
    }

    @Override
    public void requestStart(Integer requestAction) {
        showCountLoadingDialog();
    }

    @Override
    public void requestError(Integer requestAction, Throwable e) {
        //com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_ARRAY but was STRING at line 1 column 116 path $.data.Result
        toastMsg("出现异常");
        closeCountLoadingDialog();
    }

    @Override
    public void requestComplete(Integer requestAction) {

    }

    @Override
    public void responseSuccess(int requestAction, UserInfoWo userInfoWo) {
        if (userInfoWo.getStatus() == HttpConfigure.STATUS_SUCCESS){
            cardBean = userInfoWo.getUserInfo().getUserCard();
            if (cardBean == null){//代表卡已过期
                presenter.postUserCardList(REQUEST_ACTION_POST_USER_CARD_LIST, 2, -1, -1);//请求后只做提示
            } else {//未过期
                presenter.postTaskID(REQUEST_ACTION_POST_TASK_ID);
            }
        } else {
            closeCountLoadingDialog();
            toastMsg("获取用户详情失败");
        }

    }

    @Override
    public void responseSuccess(int requestAction, UserCardListWo userCardListWo) {
        if (userCardListWo.getStatus() == HttpConfigure.STATUS_SUCCESS){
            List<UserCardListWo.DataBean> dataBeanList = userCardListWo.getData();
            if (dataBeanList == null){
                toastMsg("当前国方卡已过期，请前往 我的-购国方卡 购卡");
            } else {
                if (dataBeanList.size() == 0){
                    toastMsg("当前国方卡已过期，请前往 我的-购国方卡 购卡");
                } else {
                    toastMsg("当前国方卡已过期，请前往 我的-用卡管理 激活卡");
                }
            }
        } else {
            toastMsg("获取获取用户的国方卡信息失败");
        }
        closeCountLoadingDialog();

    }

    @Override
    public void responseSuccess(int requestAction, TaskIDWo taskIDWo) {
        if (taskIDWo.getStatus() == HttpConfigure.STATUS_SUCCESS){

            TaskID = taskIDWo.getTaskID();
            //SearchType的获取：通过【查询类型】的选择
            SearchType = AlgorithmTypeConstant.getSearchTypeParamByAlgorithmType(searchTypeDefault);

            presenter.postSearchTradeMarkInfo(REQUEST_ACTION_POST_SEARCH
                    , TaskID
                    , FrontCount
                    , SearchMode
                    , SearchType
                    , Content
                    , MarkClass
                    , MarkGroup
                    , QueryMode
                    , Algorithm
                    , State
                    , DateType
                    , BeginDate
                    , EndDate );
            timer = new MyCountDownTimer();
//            timer.start();
//            toastMsg("SearchType:"+SearchType);//调试
        } else {
            closeCountLoadingDialog();
            toastMsg("获取任务ID失败");
//            toastMsg("SearchType:"+SearchType);//调试
        }

    }

    @Override
    public void responseSuccess(int requestAction, BrandItemInfoWo brandItemInfoWo) {
        if (requestAction == REQUEST_ACTION_POST_SEARCH){
//            timer.cancel();
        }
        if (brandItemInfoWo.getStatus() == HttpConfigure.STATUS_SUCCESS){

            this.brandItemInfoWo = brandItemInfoWo;
            int validMethod = cardBean.getValidMethod();
            if (validMethod == 0){//弹出dialog，输入支付密码，再支付
                closeCountLoadingDialog();
                showPasswordTaskPayDialog();
            } else if (validMethod == 1){//弹出dialog，输入验证码，再支付
                closeCountLoadingDialog();
                showValidCodeTaskPayDialog();
            } else if (validMethod == 2){//直接支付
                presenter.postTaskPay(REQUEST_ACTION_POST_TASK_PAY, TaskID, "");
            }
        } else {

/******************************注释学习错误❌弹窗信息！**********************************************/
            //      RxDialogSure rxDialogSure = new RxDialogSure(this);
            //      rxDialogSure.setContent("wangning!!!");
            //提示弹窗
            final RxDialogSure rxDialogSure = new RxDialogSure(getActivity());
            rxDialogSure.getIvLogo().setImageResource(R.drawable.logo);
            rxDialogSure.setTitle("❌错误❌");
//            rxDialogSure.setContent("json\n"+brandItemInfoWo);
            rxDialogSure.setContent("status："+brandItemInfoWo.getStatus()+"\n"+"error：\n"+brandItemInfoWo.getErr()+"\n\n'brandItemInfoWo'："+brandItemInfoWo);
            rxDialogSure.getTvSure().setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    rxDialogSure.cancel();
                }
            });
            rxDialogSure.show();
/******************************注释学习错误❌弹窗信息！**********************************************/
            //toastMsg("商标查询失败");
        }
        closeCountLoadingDialog();
    }

    @Override
    public void responseSuccess(int requestAction, StatusWo statusWo) {
        closeCountLoadingDialog();
        if (requestAction == REQUEST_ACTION_POST_TASK_PAY_CODE){
            if (statusWo.getStatus() == HttpConfigure.STATUS_SUCCESS){
                toastMsg("成功发送支付验证码");
            } else {
                toastMsg("发送支付验证码失败");
            }
        } else if (requestAction == REQUEST_ACTION_POST_TASK_PAY){
            if (statusWo.getStatus() == HttpConfigure.STATUS_SUCCESS){

                List<BrandItemInfoWo.DataBean.ResultBean> resultBeanList = brandItemInfoWo.getData().getResult();
                if (resultBeanList == null){
                    toastMsg("没对应的查询结果");
                } else {
                    if (resultBeanList.size() == 0){
                        toastMsg("没对应的查询结果");
                    } else {
                        SearchResultListActivity.start(getActivity(), brandItemInfoWo, TaskID);
                    }
                }

            } else {
                toastMsg("支付失败");
            }
        }

    }

    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (resultCode == Activity.RESULT_OK){
            switch (requestCode){
                case REQUEST_CODE_IMAGE_ELEMENT:
                    String ImageCode = data.getStringExtra(ImageElementActivity.INTENT_KEY_IMAGE_CODES);
                    etContent.setText(ImageCode);
                    break;
                case REQUEST_CODE_GET_CLASSFIY_CODE:
                    String curSelectCodeType = data.getStringExtra(ProductClassfiyActivity.INTENT_KEY_SELECT_CODE_TYPE);
                    String curSelectCode = data.getStringExtra(ProductClassfiyActivity.INTENT_KEY_SELECT_CODE);
                    if (curSelectCodeType.equals(ProductClassfiyActivity.TYPE_TYPE_CODE)){
                        if (curSelectCodeType.equals("全类")){
                            MarkClass = "";
                        } else {
                            MarkClass = curSelectCode;
                        }
                        MarkGroup = "";
                    } else {
                        MarkGroup = curSelectCode;
                        MarkClass = "";
                    }
                    tvMarkSelectValue.setText("商品服务范围："+curSelectCode);
                    break;
                case REQUEST_CODE_ALGORITHM_SELECT:
                    initAlgorithmSelect(data);
                    break;
            }
        }
    }

    private void initAlgorithmSelect(Intent data){
        String algorithmQueryMode = data.getStringExtra(AlgorithmSelectActivity.INTENT_KEY_ALGORITHM_MODE);
        List<List<String>> algorithmCodeListList = (List<List<String>>) data.getSerializableExtra(AlgorithmSelectActivity.INTENT_KEY_ALGORITHM_TYPE_LIST);
        /*测试是否加载该方法的测试信息*/
        LogUtils.d("---------------------------------------------加载：initAlgorithmSelect---------------------------------------------");
        SearchType = AlgorithmTypeConstant.getSearchTypeParamByAlgorithmType(searchTypeDefault);
        QueryMode = algorithmQueryMode;

        if (QueryMode.equals("2")){//自定义
            Algorithm = SearchType+"_"+getAlgorithmCodeStrFromList(algorithmCodeListList.get(0));
        } else {//相同或者近似
            Algorithm = "";
        }

        State = data.getStringExtra(AlgorithmSelectActivity.INTENT_KEY_FILTER_STATE);
        DateType = data.getStringExtra(AlgorithmSelectActivity.INTENT_KEY_DATA_TYPE);
        BeginDate = data.getStringExtra(AlgorithmSelectActivity.INTENT_KEY_BEGIN_DATA);
        EndDate = data.getStringExtra(AlgorithmSelectActivity.INTENT_KEY_END_DATA);

        String algorithmQueryModeName = "相同";
        String stateFilterName = "全部";
        String dateTypeName = "不过滤";
        String dateBeginToEnd = "";
        if (algorithmQueryMode.equals("2")){//自定义
            algorithmQueryModeName = "自定义";
        } else if (algorithmQueryMode.equals("1")){//近似
            algorithmQueryModeName = "近似";
        } else if (algorithmQueryMode.equals("0")){//相同
            algorithmQueryModeName = "相同";
        }
        if (State.equals("0")){
            stateFilterName = "全部";
        } else if(State.equals("1")){
            stateFilterName = "有效";
        } else if(State.equals("2")){
            stateFilterName = "无效";
        } else if(State.equals("3")){
            stateFilterName = "待定";
        }
        if (DateType.equals("0")){
            dateTypeName = "不过滤";
        } else if(DateType.equals("1")){
            dateTypeName = "申请日期";
        } else if(DateType.equals("2")){
            dateTypeName = "初审公告日期";
        } else if(DateType.equals("3")){
            dateTypeName = "注册公告日期";
        }

        tvAlgorithmSelectValue.setText("");
        tvAlgorithmSelectValue.append("查询算法："+algorithmQueryModeName+"\n");
        tvAlgorithmSelectValue.append("状态过滤："+stateFilterName+"\n");
        tvAlgorithmSelectValue.append("日期种类："+dateTypeName);
        if (!DateType.equals("0")){
            dateBeginToEnd = BeginDate+" ~ "+EndDate;
            tvAlgorithmSelectValue.append("\n日期范围："+dateBeginToEnd);
        }
    }

    private String getAlgorithmCodeStrFromList(List<String> algorithmCodeList){
        String result = "";
        for (String algorithmCode: algorithmCodeList){
            if (TextUtils.isEmpty(result)){
                result = result + algorithmCode;
            } else {
                result = result + ";" + algorithmCode;
            }
        }
        return result;
    }

    private void showPasswordTaskPayDialog(){
        if (passwordTaskPayDialog == null){
            passwordTaskPayDialog = new TaskPayDialog(getActivity(), TaskPayDialog.STATUS_PASSWORD,
                    new TaskPayDialog.OnSureClickListener(){

                        @Override
                        public void onSureClick(String value) {
                            presenter.postTaskPay(REQUEST_ACTION_POST_TASK_PAY, TaskID, MD5Uitl.getMd5Value(value));
                            passwordTaskPayDialog.dismiss();
                        }
                    });
        }
        passwordTaskPayDialog.show();
    }

    private void showValidCodeTaskPayDialog(){
        if (validCodeTaskPayDialog == null){
            validCodeTaskPayDialog = new TaskPayDialog(getActivity(), TaskPayDialog.STATUS_VALID_CODE,
                    new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            presenter.postTaskPayCode(REQUEST_ACTION_POST_TASK_PAY_CODE);
                        }
                    },
                    new TaskPayDialog.OnSureClickListener() {
                        @Override
                        public void onSureClick(String value) {
                            presenter.postTaskPay(REQUEST_ACTION_POST_TASK_PAY, TaskID, value);
                            validCodeTaskPayDialog.dismiss();
                        }
                    });
        }
    }

    private class MyCountDownTimer extends CountDownTimer {
        public MyCountDownTimer() {
            this(30000, 1000);
        }

        public MyCountDownTimer(long millisInFuture, long countDownInterval) {
            super(millisInFuture, countDownInterval);
        }

        @Override
        public void onTick(long millisUntilFinished) {

        }

        @Override
        public void onFinish() {
            /**
             * 如果30秒无数据返回，则中断改请求，执行2.4.13（请求获取商标查询结果）
             */
            presenter.dispose(REQUEST_ACTION_POST_SEARCH);
            toastMsg("后台响应时间过长，查询时间已超过30秒，无数据返回，请用户稍后通过【我的->处理进程】中对照您的查询时间进行查看后台处理结果！谢谢合作！",1);
            presenter.postSearchResultByTaskID(REQUEST_ACTION_POST_SEARCH_REULT_BY_TASK_ID, TaskID, "", 1, pageSize);
        }
    }
}
